using IntConcept.Graph;
using IntConcept;
using System.Collections.Generic;

public class Test
{
    public static void bfs<GraphType,LayerType> (GraphType g, LayerType layer,int beg)
        where GraphType:IGraph
        where  LayerType:IPropertyMap<uint>
    {
        foreach(int v in g.vertices)
            layer.set(v,~0U);
        layer.set(beg,0);
        Queue<int> q = new Queue<int>();
        q.Enqueue(beg);

        while(q.Count != 0)
        {
            int now = q.Dequeue();
            uint lnext = layer.get(now) + 1;
            foreach(EdgeInfo x in g.outgoing(now))
                if(layer.get(x.to) == ~0U)
                {
                    layer.set(x.to,lnext);
                    q.Enqueue(x.to);
                }
        }
    }

    public static void strongly_connected_components<GraphType,ComponentType> (GraphType g, ComponentType component)
        where GraphType:IGraph
        where  LayerType:IPropertyMap<uint>
    {
        foreach(int v in g.vertices)
            component.set(v,0U);

        Stack<int> przetworzone = new Stack<int>();     //FIXME

        foreach(int v in g.vertices)
            if(component.get(v) == 0)
            {
                component.set(v,~0U);
                Stack<int> q = new Stack<int>();
                q.Push(v);
                while(q.Count != 0)
                {
                    int now = q.Pop();
                    foreach(EdgeInfo x in g.outgoing(now))
                        if(layer.get(x.to) == ~0U)

                }

            }
    }

    public static void Main()
    {
        Pair<int,int>[] tab = new Pair<int,int>[]{new Pair<int,int>(0,1),new Pair<int,int>(1,2),new Pair<int,int>(2,3),new Pair<int,int>(3,4),new Pair<int,int>(4,5),new Pair<int,int>(3,6),new Pair<int,int>(2,5),new Pair<int,int>(7,8),new Pair<int,int>(8,9),new Pair<int,int>(9,7)};

        StaticGraph g = new StaticGraph(10,tab);
        StaticPropertyMap<uint> lay = new StaticPropertyMap<uint>(10);

        bfs(g,lay,0);

        foreach(int v in g.vertices)
            System.Console.WriteLine("Vertex {0}, layer {1}",v,lay.get(v));
    }
}
